<template>
	<div class="port-page">
		<div style="padding-bottom: 20px; margin-left: 20px;">
			<el-button type="warning" size="small" style='margin-right: 10px;' @click="$router.back(-1)" icon="el-icon-menu">返回</el-button>
		</div>
		<div>
			<el-row class="tac xiala">
				<el-col>
					<el-menu  background-color="#545c64" text-color="#fff"  active-text-color="#ffd04b" class="el-menu-vertical-demo" v-for="(i,index) in listbt">
						<el-menu-item index="1">
							<span slot="title">{{i.bt}}（{{i.lxmc}}）</span>
							<el-button type="text" size="mini" style="float: right;height: 100%;" @click="componentsShow('add',i)">编辑</el-button>
						</el-menu-item>
					</el-menu>
				</el-col>
				<el-col>
					<el-menu  background-color="#545c64" text-color="#fff"  active-text-color="#ffd04b" class="el-menu-vertical-demo" >
						<el-menu-item index="1">
							<span slot="title">wqweqweqweqweqwe</span>
							<el-button type="text" size="mini" style="float: right;height: 100%;" @click="componentsShow('add',i)">编辑</el-button>
						</el-menu-item>
					</el-menu>
				</el-col>
				<div style='width: 100%; float: left; text-align: center; margin-top: 10px; padding-bottom: 10px;'>
					<el-button v-if='!showtt' type="" size="small"  @click="dialogTableVisible = true" >+添加</el-button>
				</div>
			</el-row>
				<div class="zhongxin">
					<div style="height: 50px; line-height: 50px; padding-left: 20px; font-size: 20px; border-bottom: 1px solid #E8EDF0;">
						<el-button type="" size="mini"   style='margin-right: 10px;' @click="llym">预览</el-button>
					</div>
					<div style="width: 400px; background: #E8EDF0; margin-left: 200px; margin-top: 50px;" >
						<!--<div style="width: 100%;min-height: 50px; border: 1px solid white;">
						    <el-carousel height="150px">
						      <el-carousel-item v-for="item in 4" :key="item">
						        <h3>{{ item }}</h3>
						      </el-carousel-item>
						    </el-carousel>
						</div>-->
						<div  ref="mydiv" class="ql-editor" style="width: 100%;min-height: 50px; border: 1px solid white;"v-for="i in listbt" v-html='i.nr'></div>
						<!--<div style="width: 100%; height: 100px; border: 1px solid white;"></div>-->
					</div>
				</div>
		</div>
		<el-dialog title="添加段落" width="500px" :visible.sync="dialogTableVisible">
		 	<el-form label-width="100px" class="form">
		 	<el-form-item label="段落名称" >
				<el-input v-model="title" style='width: 250px;' placeholder="" icon="add"  ></el-input>
			</el-form-item>
			<el-form-item label="段落类型" >
				<el-select v-model="lx" style='width: 250px;'>
					<el-option label="纯文本" value="wb"></el-option>
					<el-option label="单图" value="tp"></el-option>
					<el-option label="轮播图" value="lbt"></el-option>
				  	<el-option label="视频" value="sp"></el-option>
					<el-option label="音频" value="yp"></el-option>
					<el-option label="表单" value="tab"></el-option>
				</el-select>
			</el-form-item>
		</el-form>
		<div style="width: 100%; text-align: center;">
			<el-button  type="primary" size="small"  @click="addtit" >保存</el-button>
			<el-button  type="warning" size="small"  @click="dialogTableVisible = false" >返回</el-button>
		</div>
		</el-dialog>
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
		<AddComponent v-if="portComponents.add.toggle" @close="componentsHide" :params="portComponents.add.params"></AddComponent>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import AddComponent from './add3'
	import qs from 'qs'
	export default {
		components: {
			LoadingComponent,
			AddComponent
		},
		data() {
			return {
				dialogTableVisible:false,
				showtt:false,
				title:'',
				lx:'',
				list1:'',
				listbt:[],
				zlid:'',
				activeNames: '',
				vkeyword: '',
				dataList: [],
				portComponents: {
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},
				},
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', '新闻资料'); //修改title
			this.$store.dispatch('changeRouterIndex', '/Marketing/xwzl'); //修改路由
			this.xwid = this.$route.query.iid + ''
			this.search(); //分页获取默认数据
			// this.getcomlist(); //加载下拉列表
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			llym(){
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					xwid:this.xwid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'readhtml', params3)
					.then(res => {
						console.log(res,81)
//						window.location.href=res.data
//						window.open(res.data);   
						window.open(res.data, '_blank');
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			addtit(){

				if(!this.title){
					this.$message.warning("请输入段落名称");
					return
				}
				if(!this.lx){
					this.$message.warning("请选择段落类型");
					return
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					lx:this.lx,
					xwid:this.xwid,
					bt:this.title,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'yxxwdl/insertbt', params3)
					.then(res => {
						console.log(res,81)
						this.dialogTableVisible  = false
						this.search();
						this.title = ''
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					xwid:this.xwid,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'yxxwdl/dllist', params3)
					.then(res => {
						console.log(res,8)
						this.listbt= res.data.data.list
//						this.list1= res.data.data.list[0].nr
						this.searchLoading = false;
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				console.log(type, data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				this.search(); //分页获取默认数据
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		margin-top: 20px;
		background: white;
		padding-top: 20px;
		padding-bottom: 20px;
		overflow: hidden;
		.xiala {
			float: left;
			border: 1px solid #E8EDF0;
			width: 15%;
			margin-left: 10px;
		}
		.jclt {
			width: 100%;
			height: 40px;
			float: left;
			font-size: 16px;
			text-align: center;
			line-height: 40px;
			border-top: 1px solid #E8EDF0;
			cursor: pointer;
		}
		.zhongxin {
			float: left;
			margin-left: 20px;
			width: 80%;
			min-height: 800px;
			border: 1px solid #E8EDF0;
		}
	}
	  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }
</style>